"""
菜单项组件
"""
from PyQt6.QtWidgets import QWidget, QLabel, QHBoxLayout
from PyQt6.QtCore import QSize
from PyQt6.QtGui import QIcon


class MenuItemWidget(QWidget):
    """菜单项组件"""
    
    def __init__(self, icon_name, text):
        super().__init__()
        layout = QHBoxLayout(self)
        # 完全移除外边距
        layout.setContentsMargins(5, 2, 5, 2)
        layout.setSpacing(5)
        
        # 创建图标标签
        icon_label = QLabel()
        icon = self.style().standardIcon(icon_name)
        icon_label.setPixmap(icon.pixmap(QSize(14, 14)))  # 缩小图标
        icon_label.setFixedWidth(14)  # 固定宽度
        icon_label.setStyleSheet("""
            QLabel {
                padding: 0px;
            }
        """)
        
        # 创建文本标签
        text_label = QLabel(text)
        text_label.setWordWrap(False)  # 禁止换行
        text_label.setStyleSheet("""
            QLabel {
                color: #595959;
                font-size: 12px;  /* 减小字体 */
                font-family: "Microsoft YaHei";
                padding: 0px;
                margin: 0px;
            }
        """)
        
        layout.addWidget(icon_label)
        layout.addWidget(text_label, 1)  # 添加拉伸因子
        layout.addStretch()
